package com.lkz.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lkz.entity.Employee;
import com.lkz.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *  前端控制器
 */
@RestController
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;
    @GetMapping("/emp")
    public Map getList(Integer page, Integer limit){
        Map<String,Object> map = new HashMap<String,Object>();
        Page<Employee> pages = new Page<Employee>();
        pages.setSize(limit);
        pages.setCurrent(page);
        IPage<Employee> iPage = employeeService.selectList(pages);
        map.put("msg","");
        map.put("count",iPage.getTotal());
        map.put("data",iPage.getRecords());
        map.put("code",0);
        return map;
    }
    @GetMapping("/emp/selectByDel")
    public Map selectByDel(Integer page, Integer limit){
        Map<String,Object> map = new HashMap<String,Object>();
        Page<Employee> pages = new Page<Employee>();
        pages.setSize(limit);
        pages.setCurrent(page);
        IPage<Employee> iPage = employeeService.selectByDel(pages);
        map.put("msg","");
        map.put("count",iPage.getTotal());
        map.put("data",iPage.getRecords());
        map.put("code",0);
        return map;
    }
    @PostMapping("/emp")
    public Map add(Employee employee,Integer roleId){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("state",employeeService.add(employee,roleId));
        return result;
    }
    @PutMapping("/edit")
    public Map edit(Employee employee,Integer roleId){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("state",employeeService.update(employee,roleId));
        return result;
    }
    @DeleteMapping("/emp/del/{empId}")
    public Map del(@PathVariable Integer empId){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("state",employeeService.del(empId));
        return result;
    }
    @DeleteMapping("/emp/recover/{empId}")
    public Map recover(@PathVariable Integer empId){
        Map<String,Object> result = new HashMap<String,Object>();
        result.put("state",employeeService.recover(empId));
        return result;
    }
    @GetMapping("/emp/getEmpList")
    public List<Employee> getEmpList(){
        return  employeeService.list();
    }
}
